<html>
<head><meta charset="utf-8"><title>layout arrays · t-lang/wg-unsafe-code-guidelines · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/index.html">t-lang/wg-unsafe-code-guidelines</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html">layout arrays</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="159141813"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159141813" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159141813">(Feb 22 2019 at 09:18)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> the example you posted already works like you expect with stride &gt; size</p>



<a name="159141839"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159141839" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159141839">(Feb 22 2019 at 09:19)</a>:</h4>
<p>I'm still not sure which extension you mean with respect to how arrays already work in Rust</p>



<a name="159141897"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159141897" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159141897">(Feb 22 2019 at 09:20)</a>:</h4>
<p>Like currently stride is always &gt;= size.</p>



<a name="159142002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142002">(Feb 22 2019 at 09:22)</a>:</h4>
<p>did you check your claim?</p>



<a name="159142003"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142003" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142003">(Feb 22 2019 at 09:22)</a>:</h4>
<p>because it doesn't seem correct: <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=f8263bc23052159dcc30470216064c17" target="_blank" title="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=f8263bc23052159dcc30470216064c17">https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=f8263bc23052159dcc30470216064c17</a></p>



<a name="159142013"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142013" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142013">(Feb 22 2019 at 09:23)</a>:</h4>
<p><code>A</code> currently has size 4</p>



<a name="159142020"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142020" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142020">(Feb 22 2019 at 09:23)</a>:</h4>
<p>AFAIK currently we always have <code>stride == size</code>. but maybe with <code>repr(packed)</code> there is a way around that? I'd be curious for an example</p>



<a name="159142021"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142021" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142021">(Feb 22 2019 at 09:23)</a>:</h4>
<p>I checked, it does have size 4 indeed</p>



<a name="159142069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142069">(Feb 22 2019 at 09:24)</a>:</h4>
<p>I specifically asked for <code>stride &gt; size</code></p>



<a name="159142071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142071">(Feb 22 2019 at 09:24)</a>:</h4>
<p>but what has that to do with arrays? If you want A to have size 3, you have to <code>packed</code> it</p>



<a name="159142074"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142074" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142074">(Feb 22 2019 at 09:24)</a>:</h4>
<p>but then it will still have <code>stride == size</code></p>



<a name="159142075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142075">(Feb 22 2019 at 09:24)</a>:</h4>
<p>as in, then both are 3</p>



<a name="159142077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142077">(Feb 22 2019 at 09:24)</a>:</h4>
<p>So do you have an example in which stride &gt; size makes sense ?</p>



<a name="159142085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142085">(Feb 22 2019 at 09:25)</a>:</h4>
<p>yes, the example I gave in the post</p>



<a name="159142092"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142092" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142092">(Feb 22 2019 at 09:25)</a>:</h4>
<p>there is no reason that <code>A</code> should have size 4</p>



<a name="159142097"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142097" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142097">(Feb 22 2019 at 09:25)</a>:</h4>
<p>In that example A has size 4,</p>



<a name="159142102"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142102" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142102">(Feb 22 2019 at 09:25)</a>:</h4>
<p>adding a byte of padding at the <em>end</em>, what good is that supposed to make?</p>



<a name="159142107"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142107" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142107">(Feb 22 2019 at 09:25)</a>:</h4>
<p>it'd make much more sense to make <code>A</code> have size 3, such that <code>(A, u8)</code> can have size 4</p>



<a name="159142115"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142115" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142115">(Feb 22 2019 at 09:25)</a>:</h4>
<p>the only reason we add padding at the end is to make <code>stride == size</code></p>



<a name="159142158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142158">(Feb 22 2019 at 09:26)</a>:</h4>
<p>when using arrays you mean ?</p>



<a name="159142161"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142161" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142161">(Feb 22 2019 at 09:26)</a>:</h4>
<p>as in, the only reason A has size 4 is because arrays don't support stride &gt; size ?</p>



<a name="159142162"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142162" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142162">(Feb 22 2019 at 09:26)</a>:</h4>
<p>well, rustc doesn't. or maybe LLVM, I don't know</p>



<a name="159142165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142165">(Feb 22 2019 at 09:26)</a>:</h4>
<p>but stride is an array-notion</p>



<a name="159142166"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142166" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142166">(Feb 22 2019 at 09:26)</a>:</h4>
<p>so I guess yes?</p>



<a name="159142168"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142168" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142168">(Feb 22 2019 at 09:27)</a>:</h4>
<p>I am confused by your question</p>



<a name="159142172"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142172" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142172">(Feb 22 2019 at 09:27)</a>:</h4>
<p>sure, but in these examples stride == size because A has size 4</p>



<a name="159142188"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142188" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142188">(Feb 22 2019 at 09:27)</a>:</h4>
<p>yes and I am saying that's silly, and we should keep open the option to do better</p>



<a name="159142191"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142191" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142191">(Feb 22 2019 at 09:27)</a>:</h4>
<p>so your question is to me that we don't want to force repr(rust) types to be larger than they need to be just because they could be put in arrays and arrays don't support stride &gt; size</p>



<a name="159142203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142203">(Feb 22 2019 at 09:27)</a>:</h4>
<p>yes</p>



<a name="159142251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142251">(Feb 22 2019 at 09:28)</a>:</h4>
<p>gotcha, i was confused because i thought that you somehow wanted, for a given size, choose a stride &gt; size</p>



<a name="159142265"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142265" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142265">(Feb 22 2019 at 09:28)</a>:</h4>
<p>well I kind of do, but those size-alignment pairs dont exist currently :P</p>



<a name="159142285"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142285" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142285">(Feb 22 2019 at 09:28)</a>:</h4>
<p>well that's what you want, i guess i was confused because I assumed that we wanted to keep padding at the end of types for other reasons</p>



<a name="159142287"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142287" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142287">(Feb 22 2019 at 09:28)</a>:</h4>
<p>basically, stride is always size rounded up to the next multiple of the alignment</p>



<a name="159142306"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142306" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142306">(Feb 22 2019 at 09:29)</a>:</h4>
<p>I am saying we should NOT hard-code that that will always be the same as size</p>



<a name="159142319"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142319" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142319">(Feb 22 2019 at 09:29)</a>:</h4>
<p>so... i think the main issue is FFI. we currently allow arrays there, they coerce to raw pointers, and C and C++ arrays don't do that</p>



<a name="159142325"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142325" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142325">(Feb 22 2019 at 09:29)</a>:</h4>
<p>I want to <em>remove</em> padding at the end of types</p>



<a name="159142338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142338">(Feb 22 2019 at 09:29)</a>:</h4>
<p>well this can only happen if you use a repr(Rust) type in FFI</p>



<a name="159142342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142342">(Feb 22 2019 at 09:29)</a>:</h4>
<p>repr(C) types will always have size be a multiple of the alignment</p>



<a name="159142426"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142426" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142426">(Feb 22 2019 at 09:31)</a>:</h4>
<p>I guess we could require arrays used in C FFI to be repr(C)</p>



<a name="159142438"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142438" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142438">(Feb 22 2019 at 09:31)</a>:</h4>
<p>but right now, using a non-repr(C) array with a non-repr(C) element type in C FFI does what C does</p>



<a name="159142484"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142484" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142484">(Feb 22 2019 at 09:32)</a>:</h4>
<p>uh, we dont give any guarantees when you use non-repr(C) types in FFI, I thought?</p>



<a name="159142493"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142493" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142493">(Feb 22 2019 at 09:32)</a>:</h4>
<p>like, to do this you need to have a <code>repr(Rust)</code> struct, and a <em>matching</em> struct in C. which is not possible, already right now.</p>



<a name="159142506"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142506" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142506">(Feb 22 2019 at 09:32)</a>:</h4>
<p>no, and we do warn about this</p>



<a name="159142511"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142511" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142511">(Feb 22 2019 at 09:33)</a>:</h4>
<p>we reorder fields, and we may change the order between rust releases</p>



<a name="159142512"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142512" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142512">(Feb 22 2019 at 09:33)</a>:</h4>
<p>(there is an improper ctypes warning)</p>



<a name="159142518"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142518" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142518">(Feb 22 2019 at 09:33)</a>:</h4>
<p>so, we <em>already</em> break such code</p>



<a name="159142534"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142534" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142534">(Feb 22 2019 at 09:33)</a>:</h4>
<p>we can't use <code>#[repr(C)]</code> on arrays yet, but that could be fixed</p>



<a name="159142601"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142601" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142601">(Feb 22 2019 at 09:34)</a>:</h4>
<p>we should definetely document repr(Rust) and repr(C) arrays differently, and leave the door open to doing something better for repr(rust)</p>



<a name="159142602"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142602" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142602">(Feb 22 2019 at 09:34)</a>:</h4>
<p>well, we wouldnt really need that. if the array element type  is <code>repr(C)</code>, the array will be compatible</p>



<a name="159142609"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142609" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142609">(Feb 22 2019 at 09:34)</a>:</h4>
<blockquote>
<p>we should definetely document repr(Rust) and repr(C) arrays differently, and leave the door open to doing something better for repr(rust)</p>
</blockquote>
<p>no need</p>



<a name="159142622"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142622" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142622">(Feb 22 2019 at 09:35)</a>:</h4>
<p>if we define arrays the way I suggested, they'll do the right thing regardless</p>



<a name="159142642"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142642" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142642">(Feb 22 2019 at 09:35)</a>:</h4>
<p>ah because repr(C) types already have padding at the end</p>



<a name="159142693"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142693" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142693">(Feb 22 2019 at 09:36)</a>:</h4>
<p>because in C they have to, because of arrays</p>



<a name="159142701"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142701" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142701">(Feb 22 2019 at 09:36)</a>:</h4>
<p>i think it is still worth calling out that if the element type of the array is repr(C), then stride == size</p>



<a name="159142827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/159142827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#159142827">(Feb 22 2019 at 09:39)</a>:</h4>
<blockquote>
<p>i think it is still worth calling out that if the element type of the array is repr(C), then stride == size</p>
</blockquote>
<p>fair</p>



<a name="160110289"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160110289" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160110289">(Mar 06 2019 at 16:21)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> the definition of stride is in the first sentence</p>



<a name="160110979"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160110979" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160110979">(Mar 06 2019 at 16:29)</a>:</h4>
<p>yes, I know? me suggesting a structure does not mean that <em>nothing</em> was at the right (in my view) place -- just a lot of it wasn't. The rest of this text is somewhat confusing (didn't get to read the latest version yet, I'll come back to you)</p>



<a name="160112014"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160112014" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160112014">(Mar 06 2019 at 16:42)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> i've reworded it trying to address both yours and <span class="user-mention" data-user-id="124289">@rkruppe</span> 's comment</p>



<a name="160112045"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160112045" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160112045">(Mar 06 2019 at 16:43)</a>:</h4>
<p>I needed to remove the mention that arrays elements are laid out contiguously in memory<br>
that only holds for <code>stride == size</code></p>



<a name="160112064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160112064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160112064">(Mar 06 2019 at 16:43)</a>:</h4>
<p>but i clarified that below</p>



<a name="160117382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160117382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160117382">(Mar 06 2019 at 17:45)</a>:</h4>
<p><span class="user-mention" data-user-id="124289">@rkruppe</span> for me personally the biggest downside of <code>stride &gt; size</code> is that it makes arrays non-contiguous</p>



<a name="160117458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160117458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160117458">(Mar 06 2019 at 17:46)</a>:</h4>
<p>but it is probably better to raise those concerns in the issues discussing such proposals</p>



<a name="160117461"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160117461" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160117461">(Mar 06 2019 at 17:46)</a>:</h4>
<p>you need an odd definition of "contiguity" to make that statement</p>



<a name="160117472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160117472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160117472">(Mar 06 2019 at 17:46)</a>:</h4>
<p>but yeah, UCG is not the place to decide about those proposals</p>



<a name="160117505"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160117505" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160117505">(Mar 06 2019 at 17:46)</a>:</h4>
<p>For me contiguity is that you can iterate over the array using <code>ptr.add(elem_size)</code>.</p>



<a name="160117530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160117530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160117530">(Mar 06 2019 at 17:47)</a>:</h4>
<p>But I see how <code>ptr.add(arr_stride)</code> is very close.</p>



<a name="160117644"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160117644" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160117644">(Mar 06 2019 at 17:48)</a>:</h4>
<p>If stride was independent from type size, as it is e.g. in matrix views, clearly it wouldn't be contiguous. But here the array is "as contiguous as it can be", and the stride is basically the element size anyway.</p>



<a name="160117821"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160117821" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160117821">(Mar 06 2019 at 17:50)</a>:</h4>
<p>right, i don;t know how much code changing this assumption would break - anyways have to go bake a cake</p>



<a name="160119025"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160119025" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160119025">(Mar 06 2019 at 18:05)</a>:</h4>
<p>the point of mentioning strie &gt; size was precisely because UCG is not the place to <em>exclude</em> such proposals</p>



<a name="160120148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160120148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160120148">(Mar 06 2019 at 18:18)</a>:</h4>
<p>Sure. I did a poor job at this initially but I hope by now I am clear that I'm not arguing for excluding this possibility now, just against putting it front and center instead of mentioning it at the end as a possibility of resolving the unspecified aspects.</p>



<a name="160120165"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160120165" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160120165">(Mar 06 2019 at 18:18)</a>:</h4>
<p>fair</p>



<a name="160178367"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160178367" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160178367">(Mar 07 2019 at 08:30)</a>:</h4>
<p>So <span class="user-mention" data-user-id="120791">@RalfJ</span> <span class="user-mention" data-user-id="124289">@rkruppe</span> i'll make the SIMD Vector thing clearer, and I'll explain what packed means. </p>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> While Cray vectors are old, they are new again. IIRC actually <span class="user-mention" data-user-id="124289">@rkruppe</span> was working on the LLVM implementation. He had a talk about it last year at EuroLLVM.</p>



<a name="160178391"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160178391" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160178391">(Mar 07 2019 at 08:31)</a>:</h4>
<p>is there a good document that explains this that you can refer to?</p>



<a name="160178393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160178393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160178393">(Mar 07 2019 at 08:31)</a>:</h4>
<p>this repo seems like the wrong place for such an explanation</p>



<a name="160179047"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160179047" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160179047">(Mar 07 2019 at 08:44)</a>:</h4>
<p>i think the portable packed SIMD RFC explained that, let me check</p>



<a name="160179085"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160179085" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160179085">(Mar 07 2019 at 08:45)</a>:</h4>
<p><a href="https://github.com/gnzlbg/rfcs/blob/ppv/text/0000-ppv.md#guide-level-explanation" target="_blank" title="https://github.com/gnzlbg/rfcs/blob/ppv/text/0000-ppv.md#guide-level-explanation">https://github.com/gnzlbg/rfcs/blob/ppv/text/0000-ppv.md#guide-level-explanation</a><br>
<a href="https://github.com/gnzlbg/rfcs/blob/ppv/text/0000-ppv.md#interaction-with-cray-vectors" target="_blank" title="https://github.com/gnzlbg/rfcs/blob/ppv/text/0000-ppv.md#interaction-with-cray-vectors">https://github.com/gnzlbg/rfcs/blob/ppv/text/0000-ppv.md#interaction-with-cray-vectors</a></p>



<a name="160179137"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160179137" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160179137">(Mar 07 2019 at 08:46)</a>:</h4>
<p>I think I can add the definition of the guide level explanation of that RFC to the packed-simd-vector.md document</p>



<a name="160179141"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160179141" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160179141">(Mar 07 2019 at 08:46)</a>:</h4>
<p>as a note, it is short enough</p>



<a name="160179156"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160179156" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160179156">(Mar 07 2019 at 08:46)</a>:</h4>
<p>maybe without mentioning cray vectors</p>



<a name="160179177"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160179177" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160179177">(Mar 07 2019 at 08:47)</a>:</h4>
<p>packed vectors -&gt; arrays, cray vectors -&gt; slices</p>



<a name="160179715"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160179715" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> gnzlbg <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160179715">(Mar 07 2019 at 08:57)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> I've added a footnote to the vector document explaining what packed means, and linking to the RFC</p>



<a name="160185843"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160185843" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Hanna Kruppe <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160185843">(Mar 07 2019 at 10:33)</a>:</h4>
<p>To give credit where credit is due, the architecture I work on (RISC-V) is just one of two recent architectures that try to bring this programming model back. Arm beat RISC-V to the punch with SVE, and I'm building on stuff Arm engineers have done previously for SVE.</p>



<a name="160212453"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout%20arrays/near/160212453" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/136281-t-lang/wg-unsafe-code-guidelines/topic/layout.20arrays.html#160212453">(Mar 07 2019 at 16:20)</a>:</h4>
<p><span class="user-mention" data-user-id="132920">@gnzlbg</span> that was in the wrong topic^^</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>